﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UserForms
{
    public partial class Form4 : Form
    {
        public Form4()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            string name = textBox1.Text;

            string pice = textBox2.Text;

            string number = numericUpDown1.Value.ToString();

            double allMoney = double.Parse(pice) * (int)numericUpDown1.Value;

            var time = DateTime.Now.ToString("yyyy/MM/dd HH:mm");

            if (name.Length != 0 && pice.Length != 0)
            {
                string sql = string.Format("insert into Shop values('{0}',{1},{2},{3},'{4}')", name, pice, number, allMoney, time);

                var w = ADOopertion.DeleteUpdateInsert(sql);
                if (w >= 1)
                {
                    MessageBox.Show("添加成功");

                    string sqlSelect = "select * from Shop";

                    Form3.StrartForm.dataGridView1.DataSource = ADOopertion.Select(sqlSelect);

                    this.Close();
                }
                else
                {
                    MessageBox.Show("添加失败");
                }
            }
            else
            {
                MessageBox.Show("请把要填写的内容填写完全！！", "提示");
            }





        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
